from pydantic import BaseModel, EmailStr, Field

# Base schema for user attributes
class UserBase(BaseModel):
    username: str = Field(..., min_length=3, max_length=50)
    email: EmailStr

# Schema for user creation (includes password)
class UserCreate(UserBase):
    password: str = Field(..., min_length=8)

# Schema for user update (fields are optional)
class UserUpdate(BaseModel):
    email: EmailStr | None = None
    password: str | None = Field(default=None, min_length=8)
    is_active: bool | None = None
    is_admin: bool | None = None

# Schema for reading user data (excludes password)
class User(UserBase):
    id: int
    is_active: bool
    is_admin: bool

    class Config:
        from_attributes = True # formerly orm_mode

# Schema just for the DB representation including hashed password
class UserInDB(User):
    password_hash: str
